]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionPrefs: Add switches to enable/disable extensions
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 26 May 2014 21:40:26 +0000 (23:40 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 27 May 2014 16:02:25 +0000 (18:02 +0200)
Bring the extension-prefs tool in line with the mockup by adding
switches to enable/disable extensions, similar to the extension
page in gnome-tweak-tool.

https://bugzilla.gnome.org/show_bug.cgi?id=730829

js/extensionPrefs/main.js

index 1dd09b1eaa4dd89faa8ae5f407b768119b9025c4..3c86498f67ee580f64fbd1ece29f8d45ccdfd203 100644 (file)
@@ -259,6 +259,12 @@ const ExtensionRow = new Lang.Class({
 
         this.uuid = uuid;
 
+        this._settings = new Gio.Settings({ schema: 'org.gnome.shell' });
+        this._settings.connect('changed::enabled-extensions', Lang.bind(this,
+            function() {
+                this._switch.state = this._isEnabled();
+            }));
+
         this._buildUI();
     },
 
@@ -294,6 +300,44 @@ const ExtensionRow = new Lang.Class({
         hbox.add(button);
 
         this.prefsButton = button;
+
+        this._switch = new Gtk.Switch({ valign: Gtk.Align.CENTER,
+                                        state: this._isEnabled() });
+        this._switch.connect('notify::active', Lang.bind(this,
+            function() {
+                if (this._switch.active)
+                    this._enable();
+                else
+                    this._disable();
+            }));
+        this._switch.connect('state-set', function() { return true; });
+        hbox.add(this._switch);
+    },
+
+    _isEnabled: function() {
+        let extensions = this._settings.get_strv('enabled-extensions');
+        return extensions.indexOf(this.uuid) != -1;
+    },
+
+    _enable: function() {
+        let extensions = this._settings.get_strv('enabled-extensions');
+        if (extensions.indexOf(this.uuid) != -1)
+            return;
+
+        extensions.push(this.uuid);
+        this._settings.set_strv('enabled-extensions', extensions);
+    },
+
+    _disable: function() {
+        let extensions = this._settings.get_strv('enabled-extensions');
+        let pos = extensions.indexOf(this.uuid);
+        if (pos == -1)
+            return;
+        do {
+            extensions.splice(pos, 1);
+            pos = extensions.indexOf(this.uuid);
+        } while (pos != -1);
+        this._settings.set_strv('enabled-extensions', extensions);
     }
 });